﻿using Game;
using Engine;

using System;
using System.Linq;

namespace ApiToolkit
{
	public class BlockProperty
	{
		public enum PropertyStatus
		{
			Normal,
			EditorNotFound
		}
		public CanvasWidget Editor
		{
			get;
			private set;
		} = null;

		private readonly Type type;
		public readonly string BindingProperty;

		public readonly string PropertyDisplayName;
		public readonly string Description;


		public BlockProperty(string propertyName, ContainerWidget parent)
		{
			Parent = parent;
			var editorName = LanguageControl.Get("BlockDataNames", propertyName, "Editor");
			switch (editorName)
			{
				case "StringPropertyEditor":
					type = typeof(string);
					break;
				case "Int32PropertyEditor":
					type = typeof(int);
					break;
				case "SinglePropertyEditor":
					type = typeof(float);
					break;
				case "BooleanPropertyEditor":
					type = typeof(bool);
					break;
				case "Vector3PropertyEditor":
					type = typeof(Vector3);
					break;
				case "BlockDigMethodPropertyEditor":
					type = typeof(BlockDigMethod);
					break;
				case "FoodTypePropertyEditor":
					type = typeof(FoodType);
					break;
			}

			BindingProperty = LanguageControl.Get("BlockDataNames", propertyName, "BindingProperty");
			PropertyDisplayName = LanguageControl.Get("BlockDataNames", propertyName, "PropertyDisplayName");
			Description = LanguageControl.Get("BlockDataNames", propertyName, "Description");

		}
		ContainerWidget Parent;

		public PropertyStatus Update(int content)
		{
			if (type == null)
			{
				return PropertyStatus.EditorNotFound;
			}
			switch (type.Name)
			{
				case "String":
					if (BindingProperty == "DefaultCategory")
					{
						Editor = new StringPropertyEditor_Category(content, BindingProperty, Parent);
						break;
					}
					Editor = new StringPropertyEditor(content, BindingProperty, Parent);
					break;
				case "Int32":
					Editor = new Int32PropertyEditor(content, BindingProperty, Parent);
					break;
				case "Single":
					Editor = new SinglePropertyEditor(content, BindingProperty, Parent);
					break;
				case "Boolean":
					Editor = new BooleanPropertyEditor(content, BindingProperty, Parent);
					break;
				case "Vector3":
					Editor = new Vector3PropertyEditor(content, BindingProperty, Parent);
					break;
				case "FoodType":
					Editor = new FoodTypePropertyEditor(content, BindingProperty, Parent);
					break;
				case "BlockDigMethod":
					Editor = new BlockDigMethodPropertyEditor(content, BindingProperty, Parent);
					break;
				default:
					return PropertyStatus.EditorNotFound;
			}
			return PropertyStatus.Normal;
		}
	}
}
